package com.suning.sawp.service.impl.store;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import com.suning.sawp.constants.LoggerConstants;
import com.suning.sawp.intf.store.CallRecordsService;
import com.suning.sawp.po.store.CallRecords;

/**
 * 
 * @author 15050519
 *
 */
@Service
public class CallRecordsServiceImpl implements CallRecordsService {

    private static final Logger LOGGER = LoggerFactory
            .getLogger(LoggerConstants.SAWP_SERVICE);
    
    @Resource
    MongoTemplate mongoTemplate;
    
    @Override
    public boolean save(CallRecords record) {
        try {
            mongoTemplate.save(record);
        } catch (DuplicateKeyException e) {
            LOGGER.error("CallRecords save DuplicateKeyException, ", e);
            return false;
        } catch (Exception e) {
            LOGGER.error("CallRecords save error, ", e);
            return false;
        }
        return true;
    }

    @Override
    public boolean batchSave(List<CallRecords> list) {
        try {
            mongoTemplate.insertAll(list);
        } catch (Exception e) {
            LOGGER.error("CallRecords batchSave error, ", e);
            return false;
        }
        return true;
    }

}
